#!/bin/sh /etc/rc.common

USE_PROCD=1
START=99

BIN=/usr/sbin/shellinaboxd
CONFDIR=/etc/shellinaboxd

append_arg() {
	local cfg="$1"
	local var="$2"
	local opt="$3"
	local def="$4"
	local val

	config_get val "$cfg" "$var"
	[ -n "$val" -o -n "$def" ] && procd_append_param command "$opt" "${val:-$def}"
}

parse_config() {
	append_arg "$1" port "-p"
}

start_service() {
	libssl=$(find /lib /usr/lib -name "libssl.so*" -type f)
	if [ -n "$libssl" ];then
		dir=$(dirname $libssl)
		libssl=$(basename $libssl)

		cd $dir
		[ ! -f libssl.so ] && ln -s $libssl libssl.so
		cd - > /dev/null
	fi

	procd_open_instance
	procd_set_param command $BIN -u root -c $CONFDIR --css=$CONFDIR/white-on-black.css
	
	config_load shellinaboxd
	config_foreach parse_config shellinaboxd
	
	procd_close_instance
}

